package com.yyds.oneservice.controller;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.yyds.common.CheckResult;
import com.yyds.common.R;
import com.yyds.common.constant.SystemConstant;
import com.yyds.common.utils.JwtUtils;
import com.yyds.oneservice.annotation.UnInterception;
import com.yyds.oneservice.pojo.UserMember;
import com.yyds.oneservice.service.IUserMemberService;
import com.yyds.oneservice.service.impl.UserMemberServiceImpl;
import com.yyds.oneservice.vo.LoginVo;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author lxy
 * @since 2022-12-12
 */
@Api(tags = "用户使用的登录功能接口")
@RestController
@RequestMapping("/userService")
public class UserMemberController {
    @Autowired
    private UserMemberServiceImpl userMemberService;
    @ApiOperation(value = "查询用户的信息方式一")
    @PostMapping("/findById")
    public R findById(Integer userid){

        UserMember byId = userMemberService.getById(userid);
        if(byId==null){
            return R.error().message("用户已经不存在或者禁止展示");
        }else{
            return R.ok().data("userdata",byId);
        }
    }
    @ApiOperation(value = "查询用户的信息方式二")
    @PostMapping("/info")
    public R info(String token){
        CheckResult checkResult = JwtUtils.validateJWT(token);

        Claims claims = checkResult.getClaims();
        System.out.println("claims    "+claims);
        // 拿到用户id
        String id = claims.getId();
        System.out.println("用户的id    "+id);
        UserMember user = userMemberService.getById(id);
        System.out.println("user信息    "+user);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("roles","['admin']");  // 咱们暂时没有 角色数据
        map.put("introduction","I am a super administrator");
        map.put("userdata",user);
        return R.ok().code(20000).data(map);
    }
}
